--Redzone RPG
--By Kylegar

include("shared.lua")


local lasttime = CurTime()

function createaccount(ply)
	ply:SetXP(0)	
	ply:SetLevel(1)
	ply:SetXPForNextLevel()	
	ply:SetSkillPoints(1)
	ply:SetPlayerMaxArmor(100)
	ply:SetPlayerMaxHealth(100)
	for k , v in pairs(BaseClasses) do
	   ply:SetBaseSkillLevel(v,0)
	end
	
	saveaccount(ply)
	
	Msg(ply:GetName().."'s account created succesfully\n")
end

function loadaccount(ply)
	local skilltab = {}
	local readstring = file.Read("Redzone/"..ply:UniqueID()..".txt")
	
	skilltab = util.KeyValuesToTable(readstring)
	
	
	
	ply:SetXP(tonumber(skilltab["xp"]))		
	ply:SetLevel(tonumber(skilltab["level"]))	
	ply:SetXPForNextLevel()
	ply:SetSkillPoints(tonumber(skilltab["sp"]))
	ply:SetBaseSkillLevel("Gunner",tonumber(skilltab["gunner"]))
	ply:SetBaseSkillLevel("Support",tonumber(skilltab["support"]))
	ply:SetBaseSkillLevel("Engineer",tonumber(skilltab["engineer"]))
	ply:SetBaseSkillLevel("Medic",tonumber(skilltab["medic"]))
	ply:SetPlayerMaxArmor(100)
	ply:SetPlayerMaxHealth(100)
	
	ply:DoBaseSkillChange() --always call this last.
	ply:PrintMessage(HUD_PRINTTALK, "Your account has been Loaded")
	Msg("\n"..ply:GetName().."'s account loaded succesfully\n")
end
	
function saveaccount(ply)
	
	Msg("saving "..ply:GetName().."'s account\n")
		
	local skilltab = {}
	skilltab["Gunner"] = ply:GetBaseSkillLevel("Gunner")
	skilltab["Support"] = ply:GetBaseSkillLevel("Support")
	skilltab["Medic"] = ply:GetBaseSkillLevel("Medic")
	skilltab["Engineer"] = ply:GetBaseSkillLevel("Engineer")
	skilltab["name"] = ply:GetName()
	skilltab["xp"] = ply:GetXP()
	skilltab["level"] = ply:GetLevel()
	skilltab["sp"] = ply:GetSkillPoints()
	local kvs = util.TableToKeyValues(skilltab)
	file.Write("Redzone/"..ply:UniqueID()..".txt",kvs)
	ply:PrintMessage(HUD_PRINTTALK, "Your account has been saved")
	Msg(ply:GetName().."'s account saved succesfully\n")
	
end
